package cn.apestar.modules.report.paymentWithdrawLog.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;

import cn.apestar.common.config.Global;
import cn.apestar.core.http.HeaderOSType;
import cn.apestar.modules.report.paymentWithdrawLog.entity.PageResponse;
import cn.apestar.modules.report.paymentWithdrawLog.entity.PaymentWithdrawLogAuditListRequest;

@Service
@Transactional(readOnly = true)
public class PaymentWithdrawLogService {

    // 用户PATH
    private static String listPath = "/common/op/paymentWithdrawLog/listForOperationPlatform";

    // 机构PATH
    private static String auditPath = "/common/op/paymentWithdrawLog/audit";

    private static SerializeConfig mapping = new SerializeConfig();

    private static String dateFormat;
    static {
        dateFormat = "yyyy-MM-dd HH:mm:ss";
        mapping.put(Date.class, new SimpleDateFormatSerializer(dateFormat));
    }

    @Autowired
    RestTemplate restTemplate;

    /**
     * 查询体现日志
     * @author lvh 2016年6月23日 上午9:18:01</br>
     * @return void
     */
    public PageResponse list(PaymentWithdrawLogAuditListRequest request) {
        String url = Global.getConfig("USER_CLEAR_URL") + listPath;
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        headers.add("site", HeaderOSType.WEB.getValue());
        HttpEntity<PaymentWithdrawLogAuditListRequest> formEntity = new HttpEntity<PaymentWithdrawLogAuditListRequest>(request, headers);
        String listString = restTemplate.postForObject(url, formEntity, String.class).toString();
        System.out.print(listString);
        PageResponse pageResponse = JSON.parseObject(listString, PageResponse.class);
        // return pageResponse.getItems();
        return pageResponse;
    }

    /**
     * 审核日志
     * @author lvh 2016年6月23日 上午9:18:01</br>
     * @return void
     */
    public void aduit(PaymentWithdrawLogAuditListRequest request) {

        String url = Global.getConfig("USER_CLEAR_URL") + auditPath;
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        headers.add("site", HeaderOSType.WEB.getValue());
        HttpEntity<PaymentWithdrawLogAuditListRequest> formEntity = new HttpEntity<PaymentWithdrawLogAuditListRequest>(request, headers);
        String listString = restTemplate.postForObject(url, formEntity, String.class);
        System.out.println(listString);
    }
}
